package main

import (
	"log"

	"github.com/micro/go-micro"
	"git.oschina.net/fanbuchi/xgggh/feeds/subscriber"
	_"git.oschina.net/fanbuchi/xgggh/feeds/database"
	feeds "git.oschina.net/fanbuchi/xgggh/feeds/srv/proto/feed"
	"git.oschina.net/fanbuchi/xgggh/feeds/handler"
)

func main() {
	// New Service
	service := micro.NewService(
		micro.Name("com.xgggh.srv.feeds"),
		micro.Version("1.0.0"),
	)
	 //https://github.com/micro/examples/blob/master/server/main.go
	/*server.Init(
		server.Name("go.micro.srv.example"),
		server.Address("45.76.xxx.yyy:8080"),
	)*/
	// Register Handler
	feeds.RegisterFeedsHandler(service.Server(), new(handler.Feed))

	// Register Struct as Subscriber
	service.Server().Subscribe(
		service.Server().NewSubscriber("topic.com.xgggh.srv.feeds", new(subscriber.Feeds)),
	)

	// Register Function as Subscriber
	service.Server().Subscribe(
		service.Server().NewSubscriber("topic.com.xgggh.srv.feeds", subscriber.Handler),
	)

	// Initialise service
	service.Init()

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
